<template>
    <div class="container">
        <div class="userinfo">
            <img src="../../../static/images/unlogin.png" alt="" v-if="!isLogIn" @click="goLogin">
            <img :src='userinfo.avatarUrl' alt="" v-else>
            <p v-if="userinfo">{{ isLogIn?userinfo.nickName:'请登录' }}</p>
        </div>
        <YearProgress></YearProgress>
        <button class="btn" @click="scanBook" v-if="isLogIn">添加图书</button>
        <!-- <button open-type="getUserInfo" lang="zh_CN" @getuserinfo="doLogin">获取用户信息</button> -->
    </div>
</template>

<script>
import YearProgress from '@/components/YearProgress'
import {getSetting, getUserInfo, request} from '@/utils'
import config from '@/config'
import { showSuccess } from '../../utils';
export default {
    data () {
        return {
            userinfo: {},
            isLogIn: false,
        }
    },
    components: {
        YearProgress
    },
    async onShow () {
        // this.isLogIn = await getSetting()
        // if (this.isLogIn) {
        //     this.userinfo = await getUserInfo()
        // } else {
        //     this.userinfo = {}
        // }

        let user = wx.getStorageSync('userInfo');
        this.isLogIn = await getSetting()
        if (user) {
            this.userinfo = user
        }
    },
    async created () {
        // debugger

    },
    methods: {
        // async addBook (isbn) {
        //     const res = await request('/weapp/addbook', 'POST', {
        //         isbn,
        //         opendid: this.userinfo.opendId
        //     })
        //     if (res.code == 0 && res.data.title) {
        //         showSuccess("添加成功", `${res.data.title}添加成功`)
        //     }
        // },
        scanBook () {
            wx.navigateTo({
                url: '/pages/addBooks/main'
            })

        },
        goLogin () { // 跳转到授权页面
            wx.navigateTo({
                url: '/pages/accredit/main'
            })
        }
    }
}
</script>

<style>

</style>
